﻿using System;
using System.Collections.Generic;
using System.Text;
using AppToolKit.Core.Context.Spring;
using Quartz;
using Quartz.Impl;
using System.Threading;
using BLL.Action.Core.Base;

namespace BLL.Action.Job
{
    [AutoWiring]
    public class JobManual
    {
        private IScheduler sched;

        [AutoWiring]
        public ContextAware ContextAwareHolder { get; set; }

        public void ManualRun(List<string> Hotels, List<string> tasks)
        {
            ISchedulerFactory sf = new StdSchedulerFactory();
            sched = sf.GetScheduler();
            JobDetail job = null;
            foreach (string key in tasks)
            {
                job = new JobDetail(key, "group1", typeof(JobHand));
                job.JobDataMap[JobDefault.Hotelid] = Hotels;
                CronTrigger trigger = new CronTrigger(key, "group1", "0/6 * * * * ?");
                
                job.JobDataMap.Add(JobBase.ContextAware_Filed, ContextAwareHolder);
                sched.ScheduleJob(job, trigger);
            }

            sched.Start();

            Thread.Sleep(1000 * 10);

            sched.Shutdown(true);

        }
    }
}
